package com.usian.behavior.controller.v1;

import com.usian.behavior.entity.ApLikesBehavior;
import com.usian.behavior.entity.ApUnlikesBehavior;
import com.usian.behavior.service.IApLikesBehaviorService;
import com.usian.behavior.service.IApUnlikesBehaviorService;
import com.usian.model.behavior.dtos.LikesBehaviorDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Fay
 * @date 2022/7/19&11:40
 */

/**
 * 查询用户的行为
 */
@RestController
@RequestMapping("/api/v1/behavior")
public class ApBehaviorController {
    @Autowired
    private IApLikesBehaviorService apLikesBehaviorService;

    @Autowired
    private IApUnlikesBehaviorService apUnlikesBehaviorService;

    @GetMapping("/findBehavior")
    public Map<String,Boolean> findBehavior(@RequestParam(name = "userId") Integer userId,
                                            @RequestParam(name = "equipmentId") String equipmentId,
                                            @RequestParam(name = "articleId") Long articleId,
                                            @RequestParam(name = "type") Integer type){

        boolean isLike = false,isUnlike=false;
//        查询点赞行为
        ApLikesBehavior apLikesBehavior = apLikesBehaviorService.findLikeByArticleId(userId, equipmentId, articleId, type);
        if (apLikesBehavior != null && apLikesBehavior.getOperation() == 1) {
            isLike = true;
        }
//       查询不喜欢行为
        ApUnlikesBehavior apUnlikesBehavior = apUnlikesBehaviorService.findUnLikeByArticleId(userId, equipmentId, articleId);
        if (apUnlikesBehavior!= null && apUnlikesBehavior.getType()==1) {
            isUnlike = true;
        }
        Map<String,Boolean> map = new HashMap<>();
        map.put("islike",isLike);
        map.put("isunlike",isUnlike);
        return map;
    }

}
